import { t } from 'i18next'
import { Modal, ModalProps } from '@kedacom/react-next'

export const Alert = (words: React.ReactNode, cb?: Function) => {
	const m = Modal.alert({
		title: t('提示'),
		onOk: () => {
			cb && cb()
			m.hide()
		},
		onCancel: () => {
			cb && cb()
			m.hide()
		},
		content: <div>{words}</div>,
		okText: t('确定'),
		cancelText: '',
	})
}

export const Confirm = (words: React.ReactNode, cb?: Function) => {
	const m = Modal.confirm({
		title: t('提示'),
		content: <div>{words}</div>,
		onOk: () => {
			cb && cb()
			m.hide()
		},
		onCancel: () => {
			m.hide()
		},
		okText: t('确定'),
		cancelText: t('取消'),
	})
}

type ConfirmModalProps = {
	/**弹窗提示的内容 */
	msg?: any
	onCancel?: Function
} & Omit<ModalProps, 'onCancel'>
/**
 * 确认弹窗
 * @param msg 弹窗提示的内容
 * @param title 弹窗的标题
 * @param onOk 点击确认按钮的回调函数
 * @param onCancel 点击取消按钮的回调函数
 * @param okText 确定按钮上的展示文本
 * @param cancelText 取消按钮上的展示文本
 */
export const confirmModal = ({
	msg,
	title = t('提示'),
	onOk,
	onCancel,
	okText = t('确定'),
	cancelText = t('取消'),
	...props
}: ConfirmModalProps) => {
	var m = Modal.confirm({
		...props,
		title: title,
		content: msg,
		className: 'confirm-wrap',
		okText: okText,
		cancelText: cancelText,
		onOk: (e) => {
			m.hide()
			onOk && onOk(e)
		},
		onCancel: (e) => {
			m.hide()
			onCancel && onCancel(e)
		},
	})
}
export default Alert
